package com.weed.common;


import com.weed.core.WeedException;
import com.weed.helper.*;
import com.weed.core.*;







/**
 * 函数说明:
 *     日志工厂，用于产生日志对象.
 *
 * 版本    修订人        说明
 * 0.1    Jason Zhuo    新增日志工厂
 */

public class ObjectFactory extends Factory {
  static  Log log  = LogFactory.getLog(ObjectFactory.class);
  
  static ObjectFactory factory = null;
  
  
  /**
   * 读取配置文件中的对象，同时初始化，返回对象。
   * @param interfaceClass
   * @return
   */
  public static Object getObject(String interfaceClass) {
    log.debug("get Object["+interfaceClass+"]");
    String implementClass = null;
    Config config = null;
    try {
      if(config == null)
        config = Configuration.config();
      if (factory == null) {
        factory = new ObjectFactory();
      }
      implementClass = config.getImplementClass(interfaceClass);
      return factory.newInstace(implementClass);
    }
    catch (Exception ex) {
        new WeedException("由于配置不正确，导出初始化失败!",ex);
    }finally{
      config = null;
    }
    return null;
  }
  public static void main(String[] args){
        //Log log1 = (Log)ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_LOG_IMPL);
        //ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_ACTION_IMPL);
        CommonInput ci = (CommonInput)ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_COMMONINPUT_IMPL);
//        ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_COMMONOUTPUT_IMPL);        
//        ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_DATAPROCESS_IMPL);        
//        ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_DATASOURCE_IMPL);                
//        ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_LOG_IMPL); 
//        ObjectFactory.getObject(com.weed.common.Environment.DEFAULT_SCRIPTEXECUTE_IMPL);         
//        ObjectFactory.getObject(com.weed.common.Environment.VERSION);                 
        ci.set("a1", "China");
        System.out.println("" + ci.get("a1"));
  }

}
